
import mx.controls.Alert;
import mx.events.CloseEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.validators.Validator;

[Embed(source="images/question.png")]private var questionIcon:Class;


public function populateData():void{	
	if(Validator.validateAll([regRollValidator]).length==0){
		var param:Object=new Object();
		param["roll_number"]=regRollText.text;
		httpStudentDetails.send(param);
	detailsPanel.visible=true;
	}else{
		regRollText.errorString="Value Required";
	}
}



private function populateStudentDetails(studentDetailsResult:XML):void{
	studentName.text=studentDetailsResult.student.student_name;
 	fatherName.text=studentDetailsResult.student.father_name;
 	motherName.text=studentDetailsResult.student.mother_name;
 	dob.text=studentDetailsResult.student.date_of_birth;
 	gender.text=studentDetailsResult.student.gender_description;
 	category.text=studentDetailsResult.student.category_description;
 	belongsToText.text=studentDetailsResult.student.entity_name;
 	programNameText.text=studentDetailsResult.student.program_name;
 	branchNameText.text=studentDetailsResult.student.branch_name;
 	specializationText.text=studentDetailsResult.student.new_specialization_description;
 	semesterText.text=studentDetailsResult.student.semester;
 	rollNoText.text=regRollText.text;
 	enrollmentNoText.text=studentDetailsResult.student.enrollment_number;
 	attemptNoText.text=studentDetailsResult.student.attempt;
 	
}

[Bindable]
public var studentDetailsResult:XML=new XML();

private function faultHandler_StudentDetails(event:FaultEvent):void
{
	mx.controls.Alert.show(event.fault.message,"Error in getting result");
}

private function resultHandler_StudentDetails(event:ResultEvent):void
{
      	studentDetailsResult=event.result as XML;
      	
      	if(studentDetailsResult.student.program_id.toString() != ""){
   	populateStudentDetails(studentDetailsResult);
      	}
}



private function cancelRegistrationAlert():void
{
	if(Validator.validateAll([reasonValidator]).length==0){
		reasonText.errorString="";
		Alert.show(commonFunction.getMessages('conformForContinue'),commonFunction.getMessages('confirm'),3,this,cancelRegistration,questionIcon);
	}else{
		reasonText.errorString="Value Required";
	}
}

private function cancelRegistration(event:CloseEvent):void
{	
if(event.detail==Alert.YES)
{
	/*
	
	CHECK status_in_semester for checking registration_status of student
	
	*/
	var param:Object=new Object();
	param["regRollNumber"]=rollNoText.text;
	param["enrolmentNumber"]=enrollmentNoText.text;
	param["reason"]=reasonText.text;
	param["studentId"]=studentDetailsResult.student.student_id;
	param["entityId"]=studentDetailsResult.student.entity_id;
	param["programId"]=studentDetailsResult.student.program_id;
	param["branchId"]=studentDetailsResult.student.branch_code;
	param["specializationId"]=studentDetailsResult.student.new_specialization;
	
	
	if(studentDetailsResult.student.status_in_semester.toString().toUpperCase()=="G"){
		Alert.show("Enrollment/roll number has already been generated for this student. Do u still want to comtinue?",commonFunction.getMessages('confirm'),3,this,cancelRegistration1,questionIcon);
	}else if(studentDetailsResult.student.status_in_semester.toString().toUpperCase()=="D"){
	Alert.show("This student's registration has already been cancelled.");
	}else if(studentDetailsResult.student.status_in_semester.toString().toUpperCase()=="M"){
		Alert.show("Cannot cancel registration of this student as data is already transferred into masters");
	}else{
		httpCancelStudentRegistration.send(param);
	}
	
}

}





  private function cancelRegistration1(event:CloseEvent):void
{	
if(event.detail==Alert.YES)
{
	var param:Object=new Object();
	param["regRollNumber"]=rollNoText.text;
	param["enrolmentNumber"]=enrollmentNoText.text;
	param["reason"]=reasonText.text;
	param["studentId"]=studentDetailsResult.student.student_id;
	param["entityId"]=studentDetailsResult.student.entity_id;
	param["programId"]=studentDetailsResult.student.program_id;
	param["branchId"]=studentDetailsResult.student.branch_code;
	param["specializationId"]=studentDetailsResult.student.new_specialization;
	
	httpCancelStudentRegistration.send(param);
	
}
}
  
  
  
  
  
  private function faultHandler_Cancel(event:FaultEvent):void
{
	mx.controls.Alert.show(event.fault.message,"Error in getting result");
}

private function resultHandler_Cancel(event:ResultEvent):void
{
      	var resultXml:XML=event.result as XML
  
   	if(resultXml.sessionConfirm == true)
             {
            Alert.show(resourceManager.getString('Messages','sessionInactive'));
          this.parentDocument.vStack.selectedIndex=0;
          this.parentDocument.loaderCanvas.removeAllChildren();
            }
            
            
regRollText.text="";
regRollText.setFocus();
detailsPanel.visible=false;	
reasonText.text="";

 Alert.show("Registration cancelled... Msg to be modified");
} 	